﻿var pageSize = 15;
var StateJson;
$(document).ready(function () {
    $.ajax({
        type: "post",
        data: { action: "GetState" },
        async: false,
        dataType: "json",
        url: "../../Ajax/PrizeConvertUserRecordAjax.ashx",
        beforeSend: function () {
        },
        success: function (data) {
            if (data != null) {
                StateJson = data.json;
            }
        },
        complete: function () {
        },
        error: function () {
        }
    });
    $("#seleByType").append(InitSelectPrizeStatus());
    PageClickFunc(1);
    $("#txtIMSI").focus(function () {
        if ($(this).val() == "输入IMSI查询") {
            $(this).val("");
        }
    });
    $("#txtIMSI").blur(function () {
        if ($(this).val() == "") {
            $(this).val($(this).attr("default"));
        }

    });
    $("#txtUserAccount").focus(function () {
        if ($(this).val() == "输入系统账号查询") {
            $(this).val("");
        }
    });
    $("#txtUserAccount").blur(function () {
        if ($(this).val() == "") {
            $(this).val($(this).attr("default"));
        }

    });
    $("#txtPrizeName").focus(function () {
        if ($(this).val() == "输入物品名称查询") {
            $(this).val("");
        }
    });
    $("#txtPrizeName").blur(function () {
        if ($(this).val() == "") {
            $(this).val($(this).attr("default"));
        }

    });
    $("#btnSele").click(function () {
        InitPrizeConvertUserRecordList(1)
    })
})
function InitSelectPrizeStatus() {
    var sel = "";
    sel+="<option>请选择</option>"
    $.each(StateJson, function (k, v) {
            sel += "<option value='" + v.value + "'>" + v.name + "</option>";
    })
    return sel;
}
PageClickFunc = function (pageclickednumber) {
    InitPrizeConvertUserRecordList(pageclickednumber);
}
function InitPrizeConvertUserRecordList(pageclickednumber) {
    var IMSI = $("#txtIMSI").val() == "输入IMSI查询" ? "" : $("#txtIMSI").val();
    var UserAccount = $("#txtUserAccount").val() == "输入系统账号查询" ? "" : $("#txtUserAccount").val();
    var PrizeName = $("#txtPrizeName").val() == "输入物品名称查询" ? "" : $("#txtPrizeName").val();
    var Stutas = $("#seleByType").val() == "请选择" ? "" : $("#seleByType").val();
    $.ajax({
        type: "post",
        data: { action: "GetList", pageIndex: pageclickednumber, pageSize: pageSize,Stutas:Stutas, IMSI: IMSI, UserAccount: UserAccount, PrizeName: PrizeName },
        datatype: "json",
        url: "../../Ajax/PrizeConvertUserRecordAjax.ashx",
        beforSend: function () {
        },
        success: function (data) {
            if (data != null) {
                var json = $.parseJSON(data).json;
                var tbody = "";
                var pageCount = $.parseJSON(data).flag;
                $.each(json, function (k, v) {
                    tbody += "<tr>"
                    tbody += "<td><lable name='lblIMSI' id='" + v.ID + "'>";
                    tbody += v.IMSI;
                    tbody += "</lable></td>";
                    tbody += "<td><lable name='lblIMEI'>";
                    tbody += v.IMEI;
                    tbody += "</lable></td>";
                    tbody += "<td><lable name='lblMAC' >";
                    tbody += v.Mac;
                    tbody += "</lable></td>";
                    tbody += "<td><lable name='lblUserAccount'>";
                    tbody += v.UserAccount;
                    tbody += "</lable></td>";
                    tbody += "<td><lable name='lblPrizeName'>";
                    tbody += v.PrizeName;
                    tbody += "</lable></td>";
                    tbody += "<td><lable name='lblCreateTime'>";
                    tbody += v.CreateTime;
                    tbody += "</lable></td>";
                    tbody += "<td><lable name='lblStutasName'>";
                    tbody += v.StutasName;
                    tbody += "</lable></td>";
                    tbody += "<td><lable name='lblPrizeCount'>";
                    tbody += v.PrizeCount;
                    tbody += "</lable></td>";
                    tbody += "</tr>"
                })
                $("#tb1").empty().append(tbody);
                $("#pager").pager({ pagenumber: pageclickednumber, pagecount: Math.ceil(pageCount / pageSize), buttonClickCallback: PageClickFunc });
            }
        },
        complete: function () {
        },
        error: function () {
        }
    })
}